import hilog from '@ohos.hilog';
import { TimeManager } from '../../time_manager/TimeManager';
import { LogLevel, LogTarget } from './LogBasedata';
import { LogTargetDailyRollingFile } from './log_target/LogTargetDailyRollingFile';

/**
 * 每次的输出事件对象.
 */
export class LogEvent {
  //控制显示的方式.
  plain: boolean = false
  context: string = ""
  level: LogLevel = LogLevel.Verbose
  target: LogTarget = LogTarget.Console
  //全部信息组合后的消息
  private message: string = ""
  // YYYY-MM-dd hh:mm:ss
  private timeString: string = ""
  //用户输入的内容.
  private content: string = ""

  constructor(logLevel: LogLevel, logTarget: LogTarget, context: string, content:string) {
    this.level = logLevel;
    this.target = logTarget;
    this.context =  context;
    this.content = content;
  }

  getTimeString():string {
    if(!this.timeString) {
      this.timeString = TimeManager.stdDateTimeStringForNow();
    }
    return this.timeString;
  }

  getMessage(): string {
    if (!this.message) {
      if (this.plain) {
        this.message = this.content;
      }
      else {
        this.message = `[${this.getTimeString()}] [${this.logLevelString()}] [${this.context}] [${this.content}]`
      }
    }
    return this.message;
  }

  logLevelString(): string {
    switch (this.level) {
      case LogLevel.Verbose:
        return "Verbose";
      case LogLevel.Info:
        return "Info";
      case LogLevel.Debug:
        return "Debug";
      case LogLevel.Warn:
        return "Warn";
      case LogLevel.Error:
        return "Error";
      case LogLevel.Fatal:
        return "Fatal";
      case LogLevel.None:
      default:
        return "";
    }
  }
}


